package chpt09;
import java.time.LocalDateTime;
import java.util.Random;
import java.util.concurrent.TimeUnit;

public class DaemonTest {
	public static void main(String[] args) {
		Thread t1 = new Thread(()-> {
			Random rnd = new Random();
			System.out.println("我是一个守护线程，偶尔播报时间");
			while(true) {
				System.out.println(LocalDateTime.now());
				try {
					TimeUnit.SECONDS.sleep(rnd.nextInt(3));
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		});
		t1.setDaemon(true);
		t1.start();
		Random rnd = new Random();
		System.out.println("t1是守护线程吗?"+t1.isDaemon());
		try {
			TimeUnit.SECONDS.sleep(rnd.nextInt(10));
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("Main线程即将结束");
	}
}
